﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Comm;

public partial class admin_page : LoginBase
{
    BLL.PageSetup bll = new BLL.PageSetup();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    public void BindData()
    {
        Model.PageSetup s = bll.GetModelBystrWhere("UserID=" + base.User.ID);
        if (s != null)
        {
            txtPic.Text = s.HomeBackground;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        Model.PageSetup ser = new Model.PageSetup();
        ser.UserID = base.User.ID;
        string Pic = (new Dispose_Image()).upLoadImage(fileupImage, "/UploadImage/PersonalityImg/" + base.User.ID + "/BackgroudImage");
        if (string.IsNullOrEmpty(Pic))
        {
            ser.HomeBackground = txtPic.Text.Trim().ToLower();
        }
        else
            ser.HomeBackground = Pic;


        int value = 0;

        Model.PageSetup s = bll.GetModelBystrWhere("UserID=" + base.User.ID);
        if (s != null)
        {
            value = bll.Update(ser, "UserID=" + base.User.ID);
            if (value > 0)
            {
                if (System.IO.File.Exists(Server.MapPath(s.HomeBackground)))
                    System.IO.File.Delete(Server.MapPath(s.HomeBackground));
            }
        }
        else
        {
            value = bll.Add(ser);
        }
        if (value > 0)
        {
            CnGine.Comm.MessageBox.AlertAndRedirect("修改背景图成功！！", "page.aspx", this.Page);
        }
        else
        {
            CnGine.Comm.MessageBox.Alert("修改背景图失败，请重试！", this.Page);
        }


    }
}